package com.lagou.homework3.one;

import java.lang.reflect.Array;
import java.util.Arrays;

public class ToStringTest {
    public static String toString(int[] arr) {
        if (arr == null){
            return "null";
        }else if (arr.length == 0){
            return "[]";
        }else{
            StringBuilder sb1 = new StringBuilder("[");
            for (int i = 0; i < arr.length; i++) {
                sb1.append(arr[i]);
                if (i == arr.length-1){
                    sb1.append("]");
                } else {
                    sb1.append(",");
                }
            }
            return sb1.toString();
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        String s1 = ToStringTest.toString(arr);
        System.out.println("s1 = " + s1);

    }
}
